// pages/user/user-balance-log/index.js
const util = require('../../../utils/util.js')
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 1充值开启
    balanceIsEntrance: app.globalData.balanceIsEntrance,
    page: {
      searchCount: false,
      current: 1,
      size: 15,
      ascs: '', //升序字段
      descs: 'create_time'
    },
    parameter: {},
    loadmore: true,
    list: [],
    userInfo: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      theme: app.globalData.theme
    });
    app.initPage()
      .then(res => {
        this.loadPage()
      })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.setData({
    //   balanceIsEntrance: app.globalData.balanceIsEntrance
    // });
    this.userInfoGet()
  },

  loadPage() {
    app.api.userBalanceLogPage(Object.assign({},
        this.data.page,
        util.filterForm(this.data.parameter)
      ))
      .then(res => {
        let list = res.data.records
        this.setData({
          list: [...this.data.list, ...list]
        })
        if (list.length < this.data.page.size) {
          this.setData({
            loadmore: false
          })
        }
      })
  },
  onReachBottom() {
    if (this.data.loadmore) {
      this.setData({
        ['page.current']: this.data.page.current + 1
      })
      this.loadPage()
    }
  },
  //获取商城用户信息
  userInfoGet() {
    app.api.userInfoGet()
      .then(res => {
        this.setData({
          userInfo: res.data
        })
      })
  },
})